package com.htfyun;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.ActivityCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Window;


import com.htfyun.fragment.toc.TOCMainFragmentAdapter;
import com.htfyun.utils.DebugLog;

import org.geometerplus.fbreader.fbreader.FBReaderApp;
import org.geometerplus.zlibrary.core.application.ZLApplication;
import org.geometerplus.zlibrary.ui.android.R;

import me.yokeyword.fragmentation.SupportActivity;
import me.yokeyword.fragmentation.SupportFragment;

/**
 * Created by sst on 2017/11/3.
 */

public class HTFYunTOCActivity extends SupportActivity {

    private TabLayout mTab;
    private Toolbar mToolbar;
    private ViewPager mViewPager;
    @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        Thread.setDefaultUncaughtExceptionHandler(new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this));

        setContentView(R.layout.htfyun_activity_toc);

        mToolbar = (Toolbar) findViewById(R.id.toolbar);

        final FBReaderApp fbreader = (FBReaderApp) ZLApplication.Instance();
        if (fbreader.getCurrentBook() != null) {
            mToolbar.setTitle(fbreader.getCurrentBook().getTitle());
        }


        mToolbar.setNavigationIcon(R.drawable.ic_arrow_back_white);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        mTab = (TabLayout) findViewById(R.id.tab);
        mViewPager = (ViewPager) findViewById(R.id.viewPager);

        mTab.addTab(mTab.newTab());
        mTab.addTab(mTab.newTab());
        mTab.addTab(mTab.newTab());
        
    }

    @Override
    protected void onResume() {
        super.onResume();
        
        String toc = getString(R.string.toc);
        String bookmark = getString(R.string.bookmark);
        String note = getString(R.string.note);
                
        mViewPager.setAdapter(new TOCMainFragmentAdapter(getSupportFragmentManager()
                , toc, bookmark, note));
        mTab.setupWithViewPager(mViewPager);
    }
}
